package com.fly.feishu.web.model.response;

import java.util.HashMap;
import java.util.Map;
/**
 * 页面响应entity
 */
public class FeishuResponse<T> extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    private T data;

    public FeishuResponse() {
        put("code", 0);
        put("msg", "success");
    }

    public FeishuResponse(T data) {
        this.data = data;
    }

    public static FeishuResponse error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static FeishuResponse error(String msg) {
        return error(500, msg);
    }

    public static FeishuResponse error(int code, String msg) {
        FeishuResponse r = new FeishuResponse();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static FeishuResponse ok(String msg) {
        FeishuResponse r = new FeishuResponse();
        r.put("msg", msg);
        r.put("code", 200);
        return r;
    }

    public static FeishuResponse ok(Map<String, Object> map) {
        FeishuResponse r = new FeishuResponse();
        r.putAll(map);
        return r;
    }

    public static FeishuResponse ok() {
        return new FeishuResponse();
    }

    public FeishuResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}